LArk.widget.bindClass(LArk.widget.BaseWidget.extend({
    options: {
        view: {
            type: "window",
            url: "view.html",
            windowOptions: {
                width: 250,
                position: {
                    top: 5,
                    right: 5,
                    bottom: 5
                }
            }
        }
    },
    drawControl: null,
    create: function () {
        this.drawControl = new LArk.Draw(this.viewer, {
            hasEdit: !0
        });
        var e = this;
        this.drawControl.on(LArk.draw.event.DrawCreated, function (t) {
            var i = t.entity;
            null != i._attribute.attr.id && "" != i._attribute.attr.id || (i._attribute.attr.id = (new Date).format("MMddHHmmss")), e.viewWindow && e.viewWindow.plotlist.plotEnd()
        }), this.drawControl.on(LArk.draw.event.EditStart, function (t) {
            var i = t.entity;
            e.startEditing(i)
        }), this.drawControl.on(LArk.draw.event.EditMovePoint, function (t) {
            var i = t.entity;
            e.startEditing(i)
        }), this.drawControl.on(LArk.draw.event.EditRemovePoint, function (t) {
            var i = t.entity;
            e.startEditing(i)
        }), this.drawControl.on(LArk.draw.event.EditStop, function (t) {
            var i = t.entity;
            e.stopEditing(i), e.saveEntity(i)
        }), this.getList()
    },
    viewWindow: null,
    winCreateOK: function (t, i) {
        this.viewWindow = i
    },
    activate: function () {
        this.drawControl.hasEdit(!0), this.drawControl.setVisible(!0)
    },
    disable: function () {
        this.viewWindow = null, this.drawControl.stopDraw(), this.lastEditEntity && (this.lastEditEntity._polyline.show = !1, this.lastEditEntity._attribute.style.show = !1, this.lastEditEntity = null), this.drawControl.hasEdit(!1), this.drawControl.setVisible(!1)
    },
    startDraw: function (t) {
        this.lastEditEntity && (this.lastEditEntity._polyline.show = !1, this.lastEditEntity._attribute.style.show = !1, this.lastEditEntity = null), this.drawControl.startDraw(t)
    },
    startEditingById: function (t) {
        var i = this.drawControl.getEntityById(t);
        null != i && (this.viewer.flyTo(i), this.drawControl.startEditing(i))
    },
    lastEditEntity: null,
    startEditing: function (t) {
        this.lastEditEntity && (this.lastEditEntity._polyline.show = !1, this.lastEditEntity._attribute.style.show = !1, this.lastEditEntity = null), (this.lastEditEntity = t)._polyline.show = !0, t._attribute.style.show = !0;
        var i = this.drawControl.getCoordinates(t);
        this.viewWindow.plotEdit.startEditing(t.attribute, i)
    },
    stopEditing: function (t) {
        this.viewWindow && this.viewWindow.plotEdit.stopEditing()
    },
    stopDraw: function () {
        this.drawControl.stopDraw()
    },
    updateAttr2map: function (t) {
        this.drawControl.updateAttribute(t)
    },
    updateGeo2map: function (t, i) {
        var e = [];
        if (i) for (var a = 0; a < t.length; a += 3) {
            var r = Cesium.Cartesian3.fromDegrees(t[a], t[a + 1], t[a + 2]);
            e.push(r)
        } else for (a = 0; a < t.length; a += 2) {
            r = Cesium.Cartesian3.fromDegrees(t[a], t[a + 1], 0);
            e.push(r)
        }
        return this.drawControl.setPositions(e), e.length <= 3 && this.centerCurrentEntity(), e
    },
    centerCurrentEntity: function () {
        var t = this.drawControl.getCurrentEntity();
        null != t && this.viewer.flyTo(t)
    },
    getGeoJson: function () {
        return this.drawControl.toGeoJSON()
    },
    jsonToLayer: function (t, i, e) {
        if (null != t) return this.drawControl.jsonToEntity(t, i, e)
    },
    deleteAll: function () {
        this.drawControl.deleteAll(), this.deleteAllData()
    },
    deleteEntity: function (t) {
        var i = this.drawControl.getEntityById(t);
        null != i && (this.delEntity(t), this.drawControl.deleteEntity(i))
    },
    deleteCurrentEntity: function () {
        var t = this.drawControl.getCurrentEntity();
        null != t && (this.delEntity(t._attribute.attr.id), this.drawControl.deleteEntity(t))
    },
    hasEdit: function (t) {
        this.drawControl.hasEdit(t)
    },
    storageName: "LArkgis_roam",
    arrFlyTable: [],
    getList: function () {
        var that = this,
            laststorage = haoutil.storage.get(this.storageName);
        if (null != laststorage && (this.arrFlyTable = eval(laststorage)), null == this.arrFlyTable || 0 == this.arrFlyTable.length) {
            this.arrFlyTable = [];
            var that = this;
            $.getJSON(this.path + "data/fly.json", function (t) {
                that.arrFlyTable = that.arrFlyTable.concat(t), that.showData(that.arrFlyTable), that.viewWindow && that.viewWindow.tableWork.loadData(this.arrFlyTable)
            })
        } else this.showData(this.arrFlyTable), this.viewWindow && this.viewWindow.tableWork.loadData(this.arrFlyTable)
    },
    showData: function (t) {
        for (var i = [], e = 0; e < t.length; e++) {
            var a = t[e];
            a.properties.style.show = !1;
            var r = {
                type: "Feature",
                properties: a.properties,
                geometry: a.geometry
            };
            r.properties.attr.id = a.id, r.properties.attr.name = a.name, i.push(r)
        }
        this.drawControl.jsonToEntity({
            type: "FeatureCollection",
            features: i
        }, !0, !1)
    },
    deleteAllData: function () {
        this.arrFlyTable = [], haoutil.storage.add(this.storageName, JSON.stringify(this.arrFlyTable)), this.isActivate && null != this.viewWindow && this.viewWindow.tableWork.loadData(this.arrFlyTable)
    },
    delEntity: function (t) {
        this.drawControl.stopDraw();
        for (var i = this.arrFlyTable.length - 1; 0 <= i; i--) if (this.arrFlyTable[i].id == t) {
            this.arrFlyTable.splice(i, 1);
            break
        }
        haoutil.storage.add(this.storageName, JSON.stringify(this.arrFlyTable)), this.isActivate && null != this.viewWindow && this.viewWindow.tableWork.loadData(this.arrFlyTable)
    },
    saveEntity: function (t) {
        null != t._attribute.attr.id && "" != t._attribute.attr.id || (t._attribute.attr.id = (new Date).format("MMddHHmmss")), null != t._attribute.attr.name && "" != t._attribute.attr.name || (t._attribute.attr.name = "路线" + t._attribute.attr.id);
        var i = this.drawControl.toGeoJSON(t);
        if (!(i.geometry.coordinates.length < 2)) {
            for (var e = {
                id: i.properties.attr.id,
                name: i.properties.attr.name,
                geometry: i.geometry,
                properties: i.properties
            }, a = !1, r = this.arrFlyTable.length - 1; 0 <= r; r--) if (this.arrFlyTable[r].id == e.id) {
                a = !0, this.arrFlyTable[r] = e;
                break
            }
            a || this.arrFlyTable.push(e), haoutil.storage.add(this.storageName, JSON.stringify(this.arrFlyTable)), this.isActivate && null != this.viewWindow && this.viewWindow.tableWork.loadData(this.arrFlyTable)
        }
    },
    toRoamFly: function (t) {
        var i = this.getFormatData(t);
        LArk.widget.activate({
            uri: "widgets/roamFly/widget.js",
            data: i
        })
        
    },
    saveForGeoJson: function (t) {
        var i = this.getFormatData(t);
        haoutil.file.downloadFile(i.name + ".json", JSON.stringify(i))
    },
    saveForCzml: function (t) {
        if (t.geometry.coordinates.length < 2) toastr.error("路线无坐标数据，无法生成！");
        else {
            var i = this.getFormatData(t),
                e = new LArk.FlyLine(this.viewer, i),
                a = JSON.stringify(e.toCZML());
            e.destroy(), haoutil.file.downloadFile(t.properties.attr.name + ".czml", a)
        }
    },
    getFormatData: function (t) {
        var i = t.properties.attr,
            e = {
                id: i.id,
                name: i.name,
                remark: i.remark,
                clockRange: i.clockRange,
                camera: {
                    type: i.cameraType,
                    followedX: i.followedX,
                    followedZ: i.followedZ
                },
                showGroundHeight: i.showGroundHeight,
                points: t.geometry.coordinates,
                speed: t.properties.speed,
                model: this.getModelCfg(i.model)
            };
        return i.showLabel && (e.label = {
            show: !0
        }), i.showLine && (e.path = t.properties.style, e.path.show = !0), i.showShadow && (e.shadow = {
            show: !0,
            type: i.shadowType
        }), e
    },
    getModelCfg: function (t) {
        switch (t) {
            case "model_car":
                return {
                    show: !0,
                    uri: "../data/gltf/qiche.gltf",
                    scale: .2,
                    minimumPixelSize: 50
                };
            case "model_air":
                return {
                    show: !0,
                    uri: "../data/gltf/feiji.glb",
                    scale: .1,
                    minimumPixelSize: 50
                };
            case "model_zhanji":
                return {
                    show: !0,
                    uri: "../data/gltf/zhanji.glb",
                    scale: .01,
                    minimumPixelSize: 50
                };
            case "model_weixin":
                return {
                    show: !0,
                    uri: "../data/gltf/weixin.gltf",
                    scale: 1,
                    minimumPixelSize: 100
                }
                case "model_wurenji":
                    return {
                        show: !0,
                        uri: "../data/gltf/wurenji.gltf",
                        scale: 1,
                        minimumPixelSize: 100
                    }
        }
        return {
            show: !1
        }
    }
}));